/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.User;
import Util.CadastroUtil;
import Util.UsuarioUtil;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import org.codehaus.jettison.json.JSONException;

@SessionScoped
@ManagedBean(name = "userBean")
public class UserBean implements Serializable {

    private List<User> filteredCars;
    public String nome;
    public int cod;
    static List<User> carsSmall;

    public UserBean() {
       populateRandomCars(carsSmall);
    }

    public int getCod() {
        return cod;
    }

    public void setCod(int cod) {
        this.cod = cod;
    }

    
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    private void populateRandomCars(List<User> list) {
        try {
            carsSmall=UsuarioUtil.getUsuario();
        } catch (JSONException ex) {
            Logger.getLogger(UserBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List<User> getFilteredCars() {
        return filteredCars;
    }

    public void setFilteredCars(List<User> filteredCars) {
        this.filteredCars = filteredCars;
    }

    public List<User> getCarsSmall() {
       // populateRandomCars(carsSmall);
        return carsSmall;
    }

    public void procuraUsuarios() {
        User us = new User();
        us.setNome(nome);
        carsSmall = UsuarioUtil.buscaUsuarios(us);
    }
    
    public void excluiUsuario() {
        User us = new User();
        us.setCod(cod);
        CadastroUtil.deletaUsuario(us);
    }
}
